package com.engr.core.service.from.impl;

import com.engr.core.service.from.FormIndexService;
import com.engr.domain.FormIndex;
import com.engr.exception.ExceptionUtils;
import com.engr.repository.form.FormIndexRepository;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.Pageable;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class FormIndexServiceImpl implements FormIndexService {

    private Logger logger = LoggerFactory.getLogger(this.getClass());

    @Autowired
    private FormIndexRepository formIndexRepository;

    @Override
    public List<FormIndex> findAllIndex() {

        List<FormIndex> result = formIndexRepository.findAll();
        if(!result.isEmpty()){
            logger.error("未查询到结果:------------{}", this.getClass().getName(), result);
            ExceptionUtils.throwServiceException("未查询到结果");
        }
        return result;
    }

    @Override
    public Page<FormIndex> findAllByPage(Pageable pageable) {

        return formIndexRepository.findAll(pageable);
    }

}
